package cn.bouncyslime.dataStructures.linearList.doubleLinkedList;

import cn.bouncyslime.dataStructures.linearList.doubleLinkedList.entity.Node;

import java.util.Random;

/**
 * 作者：张一卓
 * 创建日期：2020/9/27
 */
public class DoubleLinkedListInit {
    public static Node<Integer> integerInit(){
        int length = 5;
        Random random = new Random();
        Node<Integer> root = new Node<>();
        Node<Integer> temp = root;
        Node<Integer> prior = root;
        for (int i=0; i<length; i++){
            temp.setNext(new Node<>());
            temp = temp.getNext();
            temp.setData(random.nextInt(100));
            temp.setPrior(prior);
            prior = prior.getNext();
        }
        temp.setNext(root);
        root.setPrior(temp);
        return root;
    }

    public static Node<Integer> intArrayInit(int[] array){
        Node<Integer> root = new Node<>();
        Node<Integer> temp = root;
        Node<Integer> prior = root;
        for (int i=0; i<array.length; i++){
            temp.setNext(new Node<>());
            temp = temp.getNext();
            temp.setData(array[i]);
            temp.setPrior(prior);
            prior = prior.getNext();
        }
        temp.setNext(root);
        root.setPrior(temp);
        return root;
    }

    public static void main(String[] args) {
        Node<Integer> root = intArrayInit(new int[]{1, 3, 5, 2, 8, 10, 9});
        DoubleLinkedListUtils.printDoubleLinkedList(root);

        root = integerInit();
        DoubleLinkedListUtils.printDoubleLinkedList(root);
    }
}
